package com.example.hangzhou.welbeing.mytestdemoapp.fragment;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.transition.TransitionManager;
import android.view.View;
import android.view.ViewAnimationUtils;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.example.hangzhou.welbeing.mytestdemoapp.R;
import com.umeng.analytics.MobclickAgent;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 杭州惟君医疗科技有限公司10
 * Created by 20433 on 2018/3/13
 */

public class YouMengkActivity extends AppCompatActivity {


    @Bind(R.id.fragment_home_pager_effect_iv_planet_one)
    ImageView fragmentHomePagerEffectIvPlanetOne;
    @Bind(R.id.activity_you_meng_rl_planet_one)
    RelativeLayout activityYouMengRlPlanetOne;
    @Bind(R.id.activity_you_meng_bt_01)
    Button activityYouMengBt01;
    @Bind(R.id.activity_you_meng_bt_02)
    Button activityYouMengBt02;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_you_meng);
        ButterKnife.bind(this);
        activityYouMengRlPlanetOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                TransitionManager.beginDelayedTransition(activityYouMengRlPlanetOne);
                setViewWidth(fragmentHomePagerEffectIvPlanetOne, 1000);
            }
        });

    }

    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    private void setViewWidth(View view, int x) {
        ViewGroup.LayoutParams params = view.getLayoutParams();
        params.width = x;
        view.setLayoutParams(params);
    }

    @OnClick({R.id.activity_you_meng_bt_01, R.id.activity_you_meng_bt_02})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_you_meng_bt_01:
                doCircle(fragmentHomePagerEffectIvPlanetOne);
                break;
            case R.id.activity_you_meng_bt_02:
                hideCircle(fragmentHomePagerEffectIvPlanetOne);
                break;
        }
    }

    private void doCircle(View myView) {

        int cx = myView.getWidth() / 2;
        int cy = myView.getHeight() / 2;

        int finalRadius = Math.max(myView.getWidth(), myView.getHeight());


        Animator animation = ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);
        animation.setDuration(2000);
        myView.setVisibility(View.VISIBLE);
        animation.start();
    }

    private void hideCircle(View myView) {
        int cx = myView.getWidth() / 2;
        int cy = myView.getHeight() / 2;

        int finalRadius = myView.getWidth();

        Animator anim = ViewAnimationUtils.createCircularReveal(myView, cx, cy, finalRadius, 0);
// make the view visible and start the animation
        myView.setVisibility(View.VISIBLE);
        anim.setDuration(2000);
             /* Set a natural ease-in/ease-out interpolator. */
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.start();
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                myView.setVisibility(View.INVISIBLE);
            }
        });

    }

}
